package main

import (
	"fmt"
	"time"
)

func main() {
	// 创建一个缓冲区大小为 2 的 channel
	ch := make(chan string, 2)

	// 启动一个 goroutine 来发送数据
	go func() {
		for i := 1; i <= 3; i++ {
			data := fmt.Sprintf("Message %d", i)
			ch <- data // 向缓冲 channel 发送数据
			fmt.Println("Sending:", data)
			time.Sleep(1 * time.Second)
		}
	}()

	time.Sleep(10 * time.Second)
	for i := 0; i <= 3; i++ {
		msg := <-ch
		fmt.Println(msg)
	}

	fmt.Println("main process~")
}
